﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SpringGraph.Controls;
using MoleculeViewer.Entities;

namespace MoleculeViewer.TemplateSelectors
{
    public class MoleculeTemplateSelector : Control, IControlTemplateSelector
    {
        #region Templates
        public ControlTemplate CMoleculeTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(CMoleculeTemplateProperty);
            }
            set
            {
                SetValue(CMoleculeTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty CMoleculeTemplateProperty = DependencyProperty.Register(
            "CMoleculeTemplate", typeof(ControlTemplate), typeof(MoleculeTemplateSelector), new PropertyMetadata(null));

        public ControlTemplate NMoleculeTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(NMoleculeTemplateProperty);
            }
            set
            {
                SetValue(NMoleculeTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty NMoleculeTemplateProperty = DependencyProperty.Register(
            "NMoleculeTemplate", typeof(ControlTemplate), typeof(MoleculeTemplateSelector), new PropertyMetadata(null));


        public ControlTemplate OMoleculeTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(OMoleculeTemplateProperty);
            }
            set
            {
                SetValue(OMoleculeTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty OMoleculeTemplateProperty = DependencyProperty.Register(
            "OMoleculeTemplate", typeof(ControlTemplate), typeof(MoleculeTemplateSelector), new PropertyMetadata(null));

        public ControlTemplate HMoleculeTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(HMoleculeTemplateProperty);
            }
            set
            {
                SetValue(HMoleculeTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty HMoleculeTemplateProperty = DependencyProperty.Register(
            "HMoleculeTemplate", typeof(ControlTemplate), typeof(MoleculeTemplateSelector), new PropertyMetadata(null));


        public ControlTemplate SMoleculeTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(SMoleculeTemplateProperty);
            }
            set
            {
                SetValue(SMoleculeTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty SMoleculeTemplateProperty = DependencyProperty.Register(
            "SMoleculeTemplate", typeof(ControlTemplate), typeof(MoleculeTemplateSelector), new PropertyMetadata(null));
        #endregion

        public ControlTemplate SelectTemplate(object dataContext)
        {
            ControlTemplate template = null;

            var atom = dataContext as Atom;

            if (atom.ElementType == "C")
                template = CMoleculeTemplate;
            else if (atom.ElementType == "N")
                template = NMoleculeTemplate;
            else if (atom.ElementType == "O")
                template = OMoleculeTemplate;
            else if (atom.ElementType == "H")
                template = HMoleculeTemplate;
            else if (atom.ElementType == "S")
                template = SMoleculeTemplate;
            else
                template = CMoleculeTemplate;

            return template;
        }
    }
}
